package br.ufrgs.inf.engsoft.stp.user;

import java.io.Serializable;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;

import br.ufrgs.inf.engsoft.stp.product.Product;

@SuppressWarnings("serial")
@Entity
@Table(name = "stp_user")
public class User implements Serializable {
	 
	@Id
	@Column(name = "cpf", unique = true, nullable = false)
	private String cpf;
	
	@Column(name = "name")
	private String name;
	
	@Column(name = "rg")
	private String rg;
	
	@Column(name = "birth_date")
	private String birthDate;
	
	@Column(name = "phone")
	private String phone;
	
	@Column(name = "address")
	private String address;
	
	@Column(name = "password", nullable = false)
	private String password;
	
	@ManyToOne
    @JoinColumn(name = "role_name", nullable = false)
	private Role role;
	
	@OneToMany(mappedBy = "user")
    @Cascade({CascadeType.ALL})
    private List<Product> products; 
	
	public User() {
	}
	
	public User(String cpf) {
		this.cpf = cpf;
	}
	
	public User(String cpf, String password, Role role) {
		this.cpf = cpf;
		this.password = password;
		this.role = role;
	}
 
	public User(String cpf, String name, String rg, String birthDate, String phone,
			String address, Role role) {
		this.cpf = cpf;
		this.name = name;
		this.rg = rg;
		this.birthDate = birthDate;
		this.phone = phone;
		this.address = address;
		this.role = role;
	}
 
	public String getCpf() {
		return this.cpf;
	}
	
	public void setCpf(String cpf) {
		this.cpf = cpf;
	}
	
	public String getName() {
		return this.name;
	}
	
	public void setName(String name) {
		this.name = name;
	}
	
	public String getRg() {
		return this.rg;
	}
	
	public void setRg(String rg) {
		this.rg = rg;
	}
	
	public String getBirthDate() {
		return this.birthDate;
	}
	
	public void setBirthDate(String birthDate) {
		this.birthDate = birthDate;
	}
	
	public String getPhone() {
		return this.phone;
	}
	
	public void setPhone(String phone) {
		this.phone = phone;
	}
	
	public String getAddress() {
		return this.address;
	}
	
	public void setAddress(String address) {
		this.address = address;
	}
	
	public Role getRole() {
		return this.role;
	}
	
	public void setRole(Role role) {
		this.role = role;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public List<Product> getProducts() {
		return products;
	}

	public void setProducts(List<Product> products) {
		this.products = products;
	}
}